<template>
  <div class="app-container">
    <el-card class="box-card" style="width: 500px">
      <div slot="footer" class="dialog-footer" style="margin:20px 20px 20px 20px">
        <el-button type="warning" @click="$router.go(-1)">返 回</el-button>
      </div>

      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="教改项目" prop="courseNumber">
          {{form.villageEducationalReformName}}
        </el-form-item>
        <el-form-item label="课程号" prop="courseNumber">
          {{form.courseNumber}}
        </el-form-item>
        <el-form-item label="课题级别" prop="rank">
          {{form.rank}}
        </el-form-item>
        <el-form-item label="经费基准" prop="expenditure">
          {{form.rank}}
        </el-form-item>
        <el-form-item label="费用名称" prop="costname">
          {{form.costname}}
        </el-form-item>
        <el-form-item label="经济业务简述" prop="economicWork">
          {{form.economicWork}}
        </el-form-item>
        <el-form-item label="报销金额" prop="reportForDeletion">
          {{form.reportForDeletion}}
        </el-form-item>
        <el-form-item label="剩余经费" prop="surplusFunds">
          {{form.surplusFunds}}
        </el-form-item>
        <el-form-item label="任务书预算" prop="missionBookBudget">
          {{form.missionBookBudget}}
        </el-form-item>
        <el-form-item label="报销人" prop="reportForDeletionName">
          {{form.reportForDeletionName}}
        </el-form-item>
      </el-form>
    </el-card>





  </div>
</template>

<script>
import { listDetail, getDetail, delDetail, addDetail, updateDetail } from "@/api/village/detail";

export default {
  name: "Detail",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教改项目结课表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        courseNumber: null,
        rank: null,
        expenditure: null,
        costname: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        villageEducationalReformId: [
          { required: true, message: "教改项目id不能为空", trigger: "blur" }
        ],
        courseNumber: [
          { required: true, message: "课程号不能为空", trigger: "blur" }
        ],
        rank: [
          { required: true, message: "课题级别不能为空", trigger: "blur" }
        ],
        costname: [
          { required: true, message: "费用名称不能为空", trigger: "blur" }
        ],
        reportForDeletion: [
          { required: true, message: "报销金额不能为空", trigger: "blur" }
        ],
        reportForDeletionName: [
          { required: true, message: "报销人不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    if (this.$route.query.id != null) {
      this.handleUpdate(this.$route.query)
    }
  },
  methods: {
    /** 查询教改项目结课列表 */
    getList() {
      this.loading = true;
      listDetail(this.queryParams).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        villageEducationalReformId: null,
        courseNumber: null,
        rank: null,
        expenditure: null,
        costname: null,
        economicWork: null,
        reportForDeletion: null,
        surplusFunds: null,
        missionBookBudget: null,
        reportForDeletionName: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        isDelete: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加教改项目结课";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改教改项目结课";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDetail(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetail(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除教改项目结课编号为"' + ids + '"的数据项？').then(function() {
        return delDetail(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('village/detail/export', {
        ...this.queryParams
      }, `detail_${new Date().getTime()}.xlsx`)
    },

  }
};
</script>
